home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / updates / update15.zoo / pml / pmlsrc / log10.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-04  |  4.6 KB  |  245 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *                N O T I C E                *
  4.  *                                    *
  5.  *            Copyright Abandoned, 1987, Fred Fish        *
  6.  *                                    *
  7.  *    This previously copyrighted work has been placed into the    *
  8.  *    public domain by the author (Fred Fish) and may be freely used    *
  9.  *    for any purpose, private or commercial.  I would appreciate    *
  10.  *    it, as a courtesy, if this notice is left in all copies and    *
  11.  *    derivative works.  Thank you, and enjoy...            *
  12.  *                                    *
  13.  *    The author makes no warranty of any kind with respect to this    *
  14.  *    product and explicitly disclaims any implied warranties of    *
  15.  *    merchantability or fitness for any particular purpose.        *
  16.  *                                    *
  17.  ************************************************************************
  18.  */
  19.  
  20.  
  21. /*
  22.  *  FUNCTION
  23.  *
  24.  *    log10   double precision common log
  25.  *
  26.  *  KEY WORDS
  27.  *
  28.  *    log10
  29.  *    machine independent routines
  30.  *    math libraries
  31.  *
  32.  *  DESCRIPTION
  33.  *
  34.  *    Returns double precision common log of double precision
  35.  *    floating point argument.
  36.  *
  37.  *  USAGE
  38.  *
  39.  *    double log10 (x)
  40.  *    double x;
  41.  *
  42.  *  REFERENCES
  43.  *
  44.  *    PDP-11 Fortran IV-plus users guide, Digital Equip. Corp.,
  45.  *    1975, pp. B-3.
  46.  *
  47.  *  RESTRICTIONS
  48.  *
  49.  *    For precision information refer to documentation of the
  50.  *    floating point library routines called.
  51.  *    
  52.  *  PROGRAMMER
  53.  *
  54.  *    Fred Fish
  55.  *
  56.  *  INTERNALS
  57.  *
  58.  *    Computes log10(x) from:
  59.  *
  60.  *        log10(x) = log10(e) * log(x)
  61.  *
  62.  */
  63. #ifdef __GNUC__
  64. #  ifndef __GCC_HACK__
  65. #    define __GCC_HACK__
  66. #  endif
  67. #  if !(defined(atarist) || defined(atariminix) || defined(mc68000))
  68. #    undef __GCC_HACK__
  69. #  endif
  70. #endif
  71.  
  72. #if !defined (__M68881__) && !defined (sfp004)
  73.  
  74. #ifndef __GCC_HACK__    /* see log.c for __GCC_HACK__ */
  75. #include <stdio.h>
  76. #include <math.h>
  77. #include "pml.h"
  78.  
  79. static char funcname[] = "log10";
  80.  
  81.  
  82. double log10 (x)
  83. double x;
  84. {
  85.     return ( LOG10E * log (x) );
  86. }
  87. #endif
  88. #endif /* !__M68881__, !sfp004 */
  89.  
  90. #ifdef    sfp004
  91.  
  92. __asm("
  93.  
  94. comm =     -6
  95. resp =    -16
  96. zahl =      0
  97.  
  98. ");    /* end asm    */
  99.  
  100. #endif    sfp004
  101. #if defined (__M68881__) || defined (sfp004)
  102.  
  103.     __asm(".text; .even");
  104.  
  105. # ifdef    ERROR_CHECK
  106.  
  107.     __asm("
  108.  
  109. _Overflow:
  110.     .ascii \"OVERFLOW\\0\"
  111. _Domain:
  112.     .ascii \"DOMAIN\\0\"
  113. _Error_String:
  114.     .ascii \"log10: %s error\\n\\0\"
  115. .even
  116. | pml compatible log
  117. | m.ritzert 7.12.1991
  118. | ritzert@dfg.dbp.de
  119. |
  120. |    /* NAN  = {7fffffff,ffffffff}        */
  121. |    /* +Inf = {7ff00000,00000000}        */
  122. |    /* -Inf = {fff00000,00000000}        */
  123. |    /* MAX_D= {7fee42d1,30773b76}        */
  124. |    /* MIN_D= {ffee42d1,30773b76}        */
  125.  
  126. .even
  127. double_max:
  128.     .long    0x7fee42d1
  129.     .long    0x30273b76
  130. double_min:
  131.     .long    0xffee42d1
  132.     .long    0x30273b76
  133. NaN:
  134.     .long    0x7fffffff
  135.     .long    0xffffffff
  136. p_Inf:
  137.     .long    0x7ff00000
  138.     .long    0x00000000
  139. m_Inf:
  140.     .long    0xfff00000
  141.     .long    0x00000000
  142.     ");    /* end asm    */
  143. # endif    ERROR_CHECK
  144.  
  145.     __asm("
  146. .even
  147.     .globl _log10
  148. _log10:
  149.     ");    /* end asm    */
  150.  
  151. #endif    /* __M68881__ || sfp004    */
  152. #ifdef    __M68881__
  153.  
  154.     __asm("
  155.     flog10d    a7@(4), fp0    | log
  156.     fmoved    fp0,a7@-    | push result
  157.     moveml    a7@+,d0-d1    | return_value
  158.     ");    /* end asm    */
  159.  
  160. #endif    __M68881__
  161. #ifdef    sfp004
  162.     __asm("
  163.     lea    0xfffa50,a0
  164.     movew    #0x5415,a0@(comm)    | specify function
  165.     cmpiw    #0x8900,a0@(resp)    | check
  166.     movel    a7@(4),a0@        | load arg_hi
  167.     movel    a7@(8),a0@        | load arg_low
  168.     movew    #0x7400,a0@(comm)    | result to d0
  169.     .long    0x0c688900, 0xfff067f8    | wait
  170.     movel    a0@,d0
  171.     movel    a0@,d1
  172.     ");    /* end asm    */
  173.  
  174. #endif    sfp004
  175. #if defined (__M68881__) || defined (sfp004)
  176. # ifdef    ERROR_CHECK
  177.     __asm("
  178.     lea    double_max,a0    |
  179.     swap    d0        | exponent into lower word
  180.     cmpw    a0@(16),d0    | == NaN ?
  181.     beq    error_nan    |
  182.     cmpw    a0@(24),d0    | == + Infinity ?
  183.     beq    error_plus    |
  184.     cmpw    a0@(32),d0    | == - Infinity ?
  185.     beq    error_minus    |
  186.     swap    d0        | result ok,
  187.     rts            | restore d0
  188. ");
  189. #ifndef    __MSHORT__
  190. __asm("
  191. error_minus:
  192.     swap    d0
  193.     moveml    d0-d1,a7@-
  194.     movel    #63,_errno    | errno = ERANGE
  195.     pea    _Overflow    | for printf
  196.     bra    error_exit    |
  197. error_plus:
  198.     swap    d0
  199.     moveml    d0-d1,a7@-
  200.     movel    #63,_errno    | NAN => errno = EDOM
  201.     pea    _Overflow    | for printf
  202.     bra    error_exit    |
  203. error_nan:
  204.     moveml    a0@(24),d0-d1    | result = +inf
  205.     moveml    d0-d1,a7@-
  206.     movel    #62,_errno    | NAN => errno = EDOM
  207.     pea    _Domain        | for printf
  208. ");
  209. #else    __MSHORT__
  210. __asm("
  211. error_minus:
  212.     swap    d0
  213.     moveml    d0-d1,a7@-
  214.     movew    #63,_errno    | errno = ERANGE
  215.     pea    _Overflow    | for printf
  216.     bra    error_exit    |
  217. error_plus:
  218.     swap    d0
  219.     moveml    d0-d1,a7@-
  220.     movew    #63,_errno    | NAN => errno = EDOM
  221.     pea    _Overflow    | for printf
  222.     bra    error_exit    |
  223. error_nan:
  224.     moveml    a0@(24),d0-d1    | result = +inf
  225.     moveml    d0-d1,a7@-
  226.     movew    #62,_errno    | NAN => errno = EDOM
  227.     pea    _Domain        | for printf
  228. ");
  229. #endif    __MSHORT__
  230. __asm("
  231. error_exit:
  232.     pea    _Error_String    |
  233.     pea    __iob+52    |
  234.     jbsr    _fprintf    |
  235.     addl    #12,a7        |
  236.     moveml    a7@+,d0-d1
  237.     rts
  238.     ");
  239. # else    ERROR_CHECK
  240.  
  241. __asm("rts");
  242.  
  243. # endif    ERROR_CHECK
  244. #endif /* __M68881__ || sfp004    */
  245.